package it.gat.webservice.resource.impl;

import java.sql.SQLException;

import org.restlet.resource.Delete;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;

import it.gat.dao.PermessoUtenteDAO;
import it.gat.model.Permesso;
import it.gat.util.dao.DAOFactory;
import it.gat.webservice.utils.Impostazioni;

public class PermessoResource extends ServerResource{
	
	@Post
	public void insert(Permesso permesso) {
		DAOFactory daoFactory = DAOFactory.getDAOFactory(Integer.parseInt(Impostazioni.getProperty("DB_TYPE")));
		PermessoUtenteDAO permessoUtenteDAO = daoFactory.getPermessoUtenteDAO();
		try {
			permessoUtenteDAO.insert(permesso, getRequestAttributes().get("username").toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Delete
	public void delete(Permesso permesso) {
		DAOFactory daoFactory = DAOFactory.getDAOFactory(Integer.parseInt(Impostazioni.getProperty("DB_TYPE")));
		PermessoUtenteDAO permessoUtenteDAO = daoFactory.getPermessoUtenteDAO();
		try {
			permessoUtenteDAO.delete(permesso,(getRequestAttributes().get("username").toString()));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}
